home *** CD-ROM | disk | FTP | other *** search
/ Champak 141 / (Vol 141) Oct 17 2011.iso / Games / frantic.swf / scripts / CMG_AS3 / ScoreSubmitter.as < prev    next >
Encoding:
Text File  |  2011-10-17  |  4.1 KB  |  123 lines

  1. package CMG_AS3
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import flash.net.URLLoader;
  6.    import flash.net.URLRequest;
  7.    import flash.net.URLRequestMethod;
  8.    import flash.net.URLVariables;
  9.    
  10.    public class ScoreSubmitter extends EventDispatcher
  11.    {
  12.       
  13.       public static const RETURNCODE_SUCCESS:* = 1;
  14.       
  15.       public static var gameVersion:String = "";
  16.       
  17.       public static var gameValidationCode:String = "";
  18.       
  19.       public static const RETURNCODE_REJECTED:* = 2;
  20.       
  21.       public static const RETURNCODE_INTERNALERROR:* = 5;
  22.       
  23.       public static const URL_SUBMITSCORE:* = "http://scores.crazymonkeygames.com/hs/regscores2.php";
  24.       
  25.       public static const URL_UPDATEGAME:* = "http://scores.crazymonkeygames.com/hs/pleaseupdate.php";
  26.       
  27.       public static var gameId:uint = 0;
  28.       
  29.       public static const SCORE_RESPONSE:String = "score_response";
  30.       
  31.       public static const RETURNCODE_WORKING:* = 0;
  32.       
  33.       public static const RETURNCODE_WRONGVERSION:* = 3;
  34.       
  35.       public static const URL_VIEWSCORES:* = "http://scores.crazymonkeygames.com/hs/listscores.php";
  36.       
  37.       public static const RETURNCODE_NETWORKERROR:* = 4;
  38.        
  39.       
  40.       private var m_UrlLoader:URLLoader = null;
  41.       
  42.       public function ScoreSubmitter()
  43.       {
  44.          m_UrlLoader = null;
  45.          super();
  46.       }
  47.       
  48.       public static function loadHighScorePage() : void
  49.       {
  50.          Utilities.goToUrl(URL_VIEWSCORES + "?id=" + gameId);
  51.       }
  52.       
  53.       public static function loadUpdatePage() : *
  54.       {
  55.          Utilities.goToUrl(URL_VIEWSCORES + "?id=" + gameId);
  56.       }
  57.       
  58.       private function onIoError(param1:Event) : *
  59.       {
  60.          dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_NETWORKERROR));
  61.       }
  62.       
  63.       public function submitScore(param1:String, param2:*, param3:String = null) : void
  64.       {
  65.          var _loc4_:* = undefined;
  66.          var _loc5_:URLRequest = null;
  67.          param1 = Utilities.trim(param1);
  68.          gameVersion = Utilities.trim(gameVersion);
  69.          if(param3 == null)
  70.          {
  71.             param3 = "";
  72.          }
  73.          else
  74.          {
  75.             param3 = Utilities.trim(param3);
  76.          }
  77.          gameValidationCode = Utilities.trim(gameValidationCode);
  78.          if(gameId < 1 || gameVersion == "" || gameValidationCode == "")
  79.          {
  80.             dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_REJECTED));
  81.             return;
  82.          }
  83.          dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_WORKING));
  84.          (_loc4_ = new URLVariables()).name = param1;
  85.          _loc4_.score = param2;
  86.          _loc4_.gameId = gameId;
  87.          _loc4_.gameVersion = gameVersion;
  88.          _loc4_.special = param3;
  89.          _loc4_.key = MD5.encrypt(param1 + "|" + param2 + "|" + gameId + "|" + param3 + "|" + gameValidationCode);
  90.          (_loc5_ = new URLRequest(URL_SUBMITSCORE)).method = URLRequestMethod.POST;
  91.          _loc5_.data = _loc4_;
  92.          m_UrlLoader = new URLLoader();
  93.          m_UrlLoader.addEventListener("complete",onComplete);
  94.          m_UrlLoader.addEventListener("ioError",onIoError);
  95.          m_UrlLoader.load(_loc5_);
  96.       }
  97.       
  98.       private function onComplete(param1:Event) : void
  99.       {
  100.          var _loc2_:URLVariables = null;
  101.          var _loc3_:* = undefined;
  102.          _loc2_ = new URLVariables(m_UrlLoader.data.replace("&",""));
  103.          _loc3_ = Utilities.trim(_loc2_.ok);
  104.          if(_loc3_ == 1)
  105.          {
  106.             dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_SUCCESS));
  107.          }
  108.          else if(_loc3_ == 0)
  109.          {
  110.             dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_REJECTED));
  111.          }
  112.          else if(_loc3_ == 2)
  113.          {
  114.             dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_WRONGVERSION));
  115.          }
  116.          else
  117.          {
  118.             dispatchEvent(new ServerResponseEvent(SCORE_RESPONSE,RETURNCODE_INTERNALERROR));
  119.          }
  120.       }
  121.    }
  122. }
  123.